<?php
namespace app\staff\model;
use app\api\model\EmployeeInformation;
use think\Model;
use think\model\concern\SoftDelete;
class StaffPeople extends Model
{
    use SoftDelete;
    protected $name = "staff_people";
    protected $pk = "id";
    protected $deleteTime = "delete_time";
    protected $defaultSoftDelete = 0;
    protected $json = [];
    protected $jsonAssoc = true;
    public function getUserdata(){
        return $this->hasOne(EmployeeInformation::class,'staff_people_id','id');
    }
    public function getHeadImgAttr($value){
        if($value){
            $value = getAppFilePath($value);
        }else{
            $value = '';
        }
        return $value;
    }
    public static function StaffUpdateTime($uid){
        $bool = self::where('id',$uid)
            ->save(['up_getmessage_time'=>time(),'update_time'=>time()]);
        return $bool;
    }
    public function getExperienceAttr($value){
        if($value){
            $value = explode('|',$value);
        }else{
            $value = [];
        }
        return $value;
    }
    public static function getToken($user_id){
        $str = md5($user_id.uniqid());
        $bool = self::where('id',$user_id)
            ->save(['token'=>$str,'update_time'=>time()]);
        if($bool){
            return $str;
        }else{
            return false;
        }
    }
}